 @ECHO off
 ECHO.
 ECHO.
 
 SET ECHO_MSG_DOWNLOADING_REWIND=Downloading The Rewind Page
 SET ECHO_MSG_GETTING_DJ_SHOWS=Retrieving List Of All Currently Available DJ Shows
 SET ECHO_MSG_BUILDING_FILE_NAMES=Building List Of All Currently Available DJ Show Names
 SET ECHO_MSG_GETTING_PLAYLISTS=Retrieving List Of All The Playlists
 SET ECHO_MSG_GETTING_MP3_LOCATIONS=Retrieving List Of All MP3 File Locations
 SET ECHO_MSG_DOWNLOADING_MP3S=Downloading All The MP3 Files
 
 SET PLAYLIST_MATCHING_PART_I="embed type.*pluginspage.*src.*\.m3u"
 SET PLAYLIST_MATCHING_PART_II="http://[/A-Za-z_0-9\.\-]*.m3u"
 SET JS_MATCING="onClick=popUp('/modules/mod_rewind/player.php?recidx=[0-9]*&station=[A-Z]*')"
 SET MP3_MATCHING="http://.*[0-9][0-9].[0-9][0-9].[0-9][0-9].[0-9][0-9][0-9][0-9].mp3"

 SET FORMAT_FOR_CURL="s/\(.*\)/--url \1/"
 SET AWK_CLEAN_UP="{gsub(/onClick=popUp\(\047/,\"http://www.subspace-radio.net\");gsub(/\047\)/,\"\");print}"
 SET GREP_SHOW_NAME="<div id='dj'>[^<]*</div><div>[^<]*</div><div>[^<]*</div>"
 SET AWK_SHOW_NAME="{sub(/<div id='dj'>/,\"\")sub(/ \(c/, \"-[C\")sub(/\)/,\"]\")gsub(/<\/div><div>/,\" \")sub(/<\/div>/,\".mp3\");print}"
 SET AWK_PRINT_SHOW="{print $1\"_\"$3\"_\"$2\"_\"$4\"_\"$5\"_\"$6\"_\"$7}"
 
 SET EVE_RADIO_URL="http://www.eve-radio.com/radio/rewind/?noplayer=true"
 SET SUBSPACE_RADIO_URL="http://www.subspace-radio.net/radio/rewind"
 
 SET EVE_RADIO_PREFIX=EveRadio-
 SET SUBSPACE_RADIO_PREFIX=SubspaceRadio-
 SET TEMP=.tmp
 SET DOWNLOAD_FOLDER=EveRadioDownloads
 
 ECHO #############################################################
 ECHO ###       Downloading All Available DJ Rewind Shows       ###
 ECHO #
 ECHO #
 
 ECHO # Setting Up:
 IF NOT EXIST %DOWNLOAD_FOLDER%\NULL (
	ECHO #   Creating Download Folder: %DOWNLOAD_FOLDER% 
	MKDIR %DOWNLOAD_FOLDER% 
	ECHO #   Creating Folder Check File: %DOWNLOAD_FOLDER%\NULL
	ECHO temp > %DOWNLOAD_FOLDER%\NULL
 )
 ECHO #   Moving Into Download Folder: %DOWNLOAD_FOLDER% 
 CD %DOWNLOAD_FOLDER%
 ECHO #
 
 ECHO # Subspace Radio Section:
 ECHO #   %ECHO_MSG_DOWNLOADING_REWIND%
 curl -s %SUBSPACE_RADIO_URL% -o %SUBSPACE_RADIO_PREFIX%RewindPage%TEMP%
 
 ECHO #   %ECHO_MSG_GETTING_DJ_SHOWS%
 grep -o %JS_MATCING% %SUBSPACE_RADIO_PREFIX%RewindPage%TEMP% | sed %FORMAT_FOR_CURL% | awk %AWK_CLEAN_UP% > %SUBSPACE_RADIO_PREFIX%RewindPages2%TEMP%
 
 ECHO #   %ECHO_MSG_BUILDING_FILE_NAMES%
 grep -o %GREP_SHOW_NAME% %SUBSPACE_RADIO_PREFIX%RewindPage%TEMP% | awk %AWK_SHOW_NAME% | awk %AWK_PRINT_SHOW% | sed "s/-/_/g" > %SUBSPACE_RADIO_PREFIX%ShowNames%TEMP%
 ECHO #
 
 ECHO #   %ECHO_MSG_GETTING_PLAYLISTS%
 curl -s --config %SUBSPACE_RADIO_PREFIX%RewindPages2%TEMP% | grep -o %PLAYLIST_MATCHING_PART_I% | grep -o %PLAYLIST_MATCHING_PART_II% > %SUBSPACE_RADIO_PREFIX%ShowM3Us%TEMP%
 
 ECHO #   %ECHO_MSG_GETTING_MP3_LOCATIONS%
 sed %FORMAT_FOR_CURL% %SUBSPACE_RADIO_PREFIX%ShowM3Us%TEMP% | curl -s --config - | grep -o %MP3_MATCHING% > %SUBSPACE_RADIO_PREFIX%ShowMP3s%TEMP%
 
 ECHO #   %ECHO_MSG_DOWNLOADING_MP3S%
 wc -l SubspaceRadio-ShowMP3s.tmp | grep -o "[0-9][0-9]" > %SUBSPACE_RADIO_PREFIX%LinesToIterate%TEMP%
 SET /p LINES_TO_ITERATE=<%SUBSPACE_RADIO_PREFIX%LinesToIterate%TEMP%
 FOR /L %%A IN (1,1,%LINES_TO_ITERATE%) DO (
	eecho "url = " > finalDownload%TEMP%
	sed -n "%%Ap" %SUBSPACE_RADIO_PREFIX%ShowMP3s%TEMP% >> finalDownload%TEMP%
	eecho " output = " >> finalDownload%TEMP%
	sed -n "%%Ap" %SUBSPACE_RADIO_PREFIX%ShowNames%TEMP% >> finalDownload%TEMP%
	cat finalDownload%TEMP% | sed "{:q;N;s/\n//g;t q}" > finalDownload%TEMP%
	:: | sed "s/-o/ -o/g"
	sed -n "%%Ap" %SUBSPACE_RADIO_PREFIX%ShowNames%TEMP% > filename%TEMP%
	FOR /F %%B IN (filename%TEMP%) DO (
		IF NOT EXIST %%B EECHO -n "#     Downloading File %%A of %LINES_TO_ITERATE%"
		IF NOT EXIST %%B cat finalDownload%TEMP%
		IF NOT EXIST %%B EECHO " [COMPLETED]"
	)
 )
 
 ::DEL *%TEMP%
 
 CD ..
 ECHO #
 ECHO #############################################################
 ECHO.
 ECHO.
 @ECHO on
 
 :: curl -s $SUBSPACE_RADIO_URL | grepJS | formatForCurl | awkCleanUp | readWebsiteAll | getMp3Location | getMp3
  
 :: function awkCleanUp {
 :: awk '{gsub(/onClick=popUp\(\047/,"http://www.subspace-radio.net");gsub(/\047\)/,"");print}' %1
 :: }

 :: function readWebsiteURL {
 :: SET WEBSITE_URL=%1
 :: curl -s %WEBSITE_URL% | grep -o %FIRST_REGEX% | grep -o %SECOND_REGEX% 
 :: }

 :: function readWebsiteAll {
 :: curl -s --config - | grep -o %FIRST_REGEX% | grep -o %SECOND_REGEX% 
 :: }

 :: function getMp3Location {
 :: formatForCurl $1 | curl -s --config - | grep -o "$MP3_MATCHING_REGEX"
 :: }

 :: function getMp3 {
 :: formatForCurl $1 | curl --remote-name-all --limit-rate 1M --config -
 :: }

 :: function formatForCurl {
 :: sed "s/\(.*\)/--url \1/" $1
 :: }

 :: function grepJS{
 ::  grep -o "$JS_MATCING_REGEX" $1
 :: }
